package mypackage;

import java.math.BigDecimal;
import java.text.DateFormat;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.*;
import java.util.stream.Collectors;

public class StringTest {

    public static void main(String[] args) {
        //String str = "hello nihao";
        //String[] strArr = str.split(" ");
        //System.out.println(Arrays.toString(strArr));
        //
        //String str1 = "info this is a info message.";
        //String substring = str1.substring(0, str1.indexOf(" "));
        //System.out.println(substring);
        //System.out.println(str1.substring(str1.indexOf(" ")+1));
        
        //test();
        
        //test1();
        
        //test2();
        
        //test3();
        
        //test4();
        
        //test5();
        //test6();
        //test7();
        // test8();
        // test9();
        // test10();
        // test11();
        // test12();
        // test13();
        // test14();
        // test15();
        test16();
    }

    private static void test16() {
        DeleteImagesRequest deletedImageRequest = new DeleteImagesRequest();
        String simpleName = deletedImageRequest.getClass().getSimpleName();
        System.out.println("simpleName = " + simpleName);
        int index = simpleName.lastIndexOf("Request");
        System.out.println("request = " + index);
        String substring = simpleName.substring(0, index);
        System.out.println("substring = " + substring);
    }

    private static void test15() {
        List<String> list = new ArrayList<>();
        for (String s : list) {
            System.out.println("s = " + s);
        }

        String str = DateFormat.getDateTimeInstance(2, 2, Locale.CHINESE).format(new java.util.Date());
        System.out.println("str = " + str);
    }

    private static void test14() {
        int year = ZonedDateTime.now(ZoneOffset.UTC).getYear();
        System.out.println("year = " + year);
        int monthValue = ZonedDateTime.now(ZoneOffset.UTC).getMonthValue();
        System.out.println("monthValue = " + monthValue);
        String period = year + String.format("%02d", monthValue);
        System.out.println("period = " + period);
    }
    
    


    private static void test13() {
        // 获取当前的年和月
        int year = ZonedDateTime.now().getYear();
        int month = ZonedDateTime.now().getMonth().getValue();
        System.out.println(year+"---"+month);

        // 一个月的开始时间和结束时间
        ZonedDateTime zonedDateTimeMonth = ZonedDateTime.of(year, month, 1, 0, 0, 0, 0, ZoneOffset.of("+08:00"));
        long monthBeginTime = zonedDateTimeMonth.withZoneSameInstant(ZoneOffset.UTC).toEpochSecond() * 1000; // 月开始时间

        String s = new Date(monthBeginTime).toLocaleString();
        System.out.println("s = " + s);

        long monthEndTime = zonedDateTimeMonth.plusMonths(1).withZoneSameInstant(ZoneOffset.UTC).toEpochSecond() * 1000;// 月结束时间

        String s1 = new Date(monthEndTime).toLocaleString();
        System.out.println("s1 = " + s1);

        System.out.println("月开始时间："+monthBeginTime);
        System.out.println("月结束时间："+monthEndTime);

        // 一年开始时间和结束时间
        ZonedDateTime zonedDateTimeYear = ZonedDateTime.of(year, 01, 01, 0, 0, 0, 0, ZoneOffset.of("+08:00"));
        long yearBeginTimestamp = zonedDateTimeYear.withZoneSameInstant(ZoneOffset.UTC).toEpochSecond() * 1000;// 年开始时间
        long yearEndTimestamp = zonedDateTimeYear.plusYears(1).withZoneSameInstant(ZoneOffset.UTC).toEpochSecond() * 1000; // 年结束时间
        String s2 = new Date(yearBeginTimestamp).toLocaleString();
        String s3 = new Date(yearEndTimestamp).toLocaleString();
        System.out.println("年开始时间："+s2);
        System.out.println("年结束时间："+s3);

    }

    private static void test12() {
        List<String> list1 = new ArrayList<>();
        list1.add("1");
        list1.add("2");
        list1.add("3");
        list1.add("5");

        List<String> list2 = new ArrayList<>();
        list2.add("2");
        list2.add("4");
        list2.add("5");
        list2.add("6");

        list1.retainAll(list2);

        list1.stream().forEach(System.out::println);
        System.out.println("---");
        list2.stream().forEach(System.out::println);
    }

    private static void test11() {
        List<String> list = new ArrayList<>();
        list.add("1");
        list.add("2");
        list.add("3");
        System.out.println("list = " + list);
    }

    /**
     * 找出阈值相同的用户有哪些
     */
    private static void test10() {
        Map<String,Integer> distinctBillingUsersMap = new HashMap<>();
        distinctBillingUsersMap.put("shg101", 10);  // key:用户名，value:用户设置的余额阈值
        distinctBillingUsersMap.put("shg102", 11);
        distinctBillingUsersMap.put("shg103", 12);
        distinctBillingUsersMap.put("shg104", 13);
        distinctBillingUsersMap.put("shg105", 14);
        distinctBillingUsersMap.put("shg106", 11);


        // Set<Map.Entry<String, Integer>> entries = distinctBillingUsersMap.entrySet();
        // for (Map.Entry<String, Integer> entry : entries) {
        //     System.out.println(entry);
        // }
        //
        // Map<Integer, List<Map.Entry<String, Integer>>> collect = entries.stream().collect(Collectors.groupingBy(Map.Entry::getValue));

        // 上面注释的这段代码等同于下面这行代码
        Map<Integer, List<Map.Entry<String, Integer>>> alertThresholdsMap = distinctBillingUsersMap.entrySet()
                .stream()
                .collect(Collectors.groupingBy(Map.Entry::getValue));

        System.out.println("alertThresholdsMap = " + alertThresholdsMap);

        alertThresholdsMap.forEach((key,value) ->{
            List<String> distinctBillingUsers = value.stream().map(Map.Entry::getKey).collect(Collectors.toList());
            System.out.println(key.floatValue()+"---> distinctBillingUsers = " + distinctBillingUsers);
        });
    }

    private static void test9() {
        String format = String.format("</br>Deduct coupon amount:%.3f", 0.0270556);
        System.out.println("format = " + format);
    }

    private static void test8() {
        String m = "^[0-9]*$";
        String str = "3";
        boolean flag = str.matches(m);
        if (flag){
            System.out.println("正整数");
        }else{
            System.out.println("不是正整数");
        }
    }

    private static void test7(){
        String str = "Benny";
        String s1 = str.split(" ")[0];
        System.out.println("s1 = " + s1);
    }

    private static void test6(){
        BigDecimal bigDecimal = BigDecimal.ZERO;
        BigDecimal bigDecimal1 = BigDecimal.ZERO;
        System.out.println(bigDecimal.compareTo(bigDecimal1));
    }

    private static void test5() {
        System.out.println("git test1"); // master test
    }

    private static void test4() {
        String replace = UUID.randomUUID().toString().replace("-", ""); // develop test
        System.out.println(replace);
    }

    private static void test3() {
        String str = null;
        System.out.println(str.toString());
    }

    private static void test2() {
        
        String str = "../";
        System.out.println(str.length());
    }

    private static void test1() {
        
        String versionNumber = "6.1.8";
        String[] split = versionNumber.split("\\.");
        for(int i=0;i<split.length;i++){
            System.out.println(split[i]);
        }
    }

    private static void test() {
        
        String str = "开始上传渠道包:Jumi_vhuawei_14_v5.4.1_541.apk\n" +
                "渠道包上传成功：Jumi_vhuawei_14_v5.4.1_541/Jumi_vhuawei_14_v5.4.1_541.apk\n" +
                "[BINGO:URL]https://example-bucket-shg-1.oss-cn-shenzhen.aliyuncs.com/Jumi_vhuawei_14_v5.4.1_541/Jumi_vhuawei_14_v5.4.1_541.apk\n" +
                "shutdown OSS-client successfully!";

        int beginIndex = str.indexOf("[BINGO:URL]");
        System.out.println("beginIndex"+beginIndex);
        int endIndex = str.lastIndexOf("shutdown OSS-client successfully!");
        System.out.println("endIndex: "+endIndex);

        System.out.println(str.substring(beginIndex+"[BINGO:URL]".length(),endIndex));
        

        System.out.println(str.substring(str.indexOf("https"),str.lastIndexOf(".apk")+".apk".length()));

    }
}
